-- ----------------------------
-- TABLE STRUCTURE FOR SYS_DEPT  增加部门表
-- ----------------------------
CREATE TABLE  "SYS_DEPT" (
"DEPT_ID" NUMBER(20) NOT NULL ,
"PARENT_ID" NUMBER(20) NOT NULL ,
"NAME" NVARCHAR2(20) NOT NULL ,
"ORDER_NUM" NUMBER(11) NULL ,
"DEL_FLAG" NUMBER(11) NULL
)
LOGGING
NOCOMPRESS
NOCACHE

;
COMMENT ON TABLE  "SYS_DEPT" IS '部门管理';
COMMENT ON COLUMN  "SYS_DEPT"."PARENT_ID" IS '上级部门ID，一级部门为0';
COMMENT ON COLUMN  "SYS_DEPT"."NAME" IS '部门名称';
COMMENT ON COLUMN  "SYS_DEPT"."ORDER_NUM" IS '排序';
COMMENT ON COLUMN  "SYS_DEPT"."DEL_FLAG" IS '是否删除  -1：已删除  0：正常';



ALTER TABLE  "SYS_DEPT" ADD PRIMARY KEY ("DEPT_ID");


create sequence sys_dept_id_seq increment by 1 start with 1 nomaxvalue nominvalue nocache;

create or replace trigger tr_sys_dept before insert on SYS_DEPT for each row
begin
select sys_dept_id_seq.nextval into :new.DEPT_ID from dual;
end;


alter table SYS_USER add (DEPT_ID NUMBER(20));